<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <button>发送请求</button>
    <script>
        let btn = document.querySelector('button');
        //添加请求拦截器
        axios.interceptors.request.use(config => {
            // config 为配置对象
            console.log('请求拦截器成功')
            //准备工作, 公共参数 vip=1
            config.params = {
                vip: 1
            }
            //必须要返回配置对象
            return config;
            // return Promise.reject('参数错误');
        }, error => {
            console.log('请求拦截器失败');
            return Promise.reject(error);
        });

        //为 axios 添加响应拦截器  res 完整的响应结果对象 {status, statusText, headers, data}
        axios.interceptors.response.use(res => {
            //成功
            console.log('响应拦截器成功');
            //返回
            return res.data;
        }, error => {
            //
            console.log('响应拦截器失败');
            //中断 promise 链条
            return new Promise(() => {});
        });

        //绑定事件, 发送请求
        btn.onclick = function(){
            // axios 的默认请求类型为 get
            axios({
                url: 'http://127.0.0.1:8090/movie',
            }).then(v => {
                console.log(v)
            });
        }

    </script>
</body>
</html>